﻿using System.Web.Mvc;
using LenderDocs.Service;
using LenderDocs.ViewModels;

namespace LenderDocs.Web.Controllers
{
    public class LenderDocController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult SignUp()
        {
            return View();
        }

        [HttpPost]
        public ActionResult RequestDocumentPackage(LenderDocRequest lenderDocRequest)
        {
            var svc = new LenderDocsAppService();
            if (lenderDocRequest.IsAttorney) //Email the request
            {
                svc.EmailRequest(lenderDocRequest);
            }
            else
            {
                //Send model to view that will contain a number of hidden fields and will perform a submit to cart
                return AddToCart(lenderDocRequest);
            }

            AddUserMessage("Your request was successful.  You will be contacted within 1 business day for details.");

            return RedirectToAction("Index");
        }

        public ActionResult AddToCart(LenderDocRequest lenderDocRequest)
        {
            return View("AddToCart", lenderDocRequest);
        }

        private void AddUserMessage(string userMessageText)
        {
            var userMessage = new UserMessage();
            userMessage.InfoMessages.Add(userMessageText);
            TempData["UserMessage"] = userMessage;
        }
    }
}
